需要启用 Windows Media Player 功能,否则会提示【System.Runtime.InteropServices.COMException:“没有注册类】操作步骤:控制面板>>程序>>启用或者关闭windows 功能>>选中 媒体功能>>Windows Media Player,点击确定即可
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Kuade.WindowsFormsApp1{ /// <summary> /// /// </summary> public partial class FrmMainForm :Form { /// <summary> /// 构造函数 /// </summary> public FrmMainForm() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { axWindowsMediaPlayer1.URL = this.textBox1.Text; axWindowsMediaPlayer1.Ctlcontrols.play(); } private void button2_Click(object sender, EventArgs e) { OpenFileDialog opf = new OpenFileDialog(); //获取用户的文件路径,可以使用对话框的形式获得。 if (opf.ShowDialog() == DialogResult.OK)//显示对话框获取用户信息 { textBox1.Text = opf.FileName; } } private void FrmMainForm_Load(object sender, EventArgs e) { axWindowsMediaPlayer1.Ctlcontrols.play(); } }}
评论